<?php

class Application_Model_Compatible extends Zend_Db_Table_Abstract
{
    protected $_name = "kp_compatible"; //Ten bang
    protected $_primary = "cp_id"; //Khoa chinh
    protected $db;
    //Cac truong du lieu
    var $cp_id;
    var $os_id;
    var $cp_name;
    var $cp_status=0;
    
    //Ham khoi tao
    public function __construct(){
    	$this->db = Zend_Registry::get('db');
    }
    
    //Get all user
    public function getAll(){
    	$query = $this->db->select();
    	$query->from($this->_name.' as cp');
    	$query->join('kp_os as os','os.os_id = cp.os_id',array('os.os_id','os.os_name'));
    	$query->order(array('os_name','cp_name'));
    	return $this->db->fetchAll($query);
    }
    public function getAllByOS($id){
        $query = $this->db->select();
        $query->from($this->_name.' as cp');
        $query->join('kp_os as os','os.os_id = cp.os_id',array());
        $query->where('cp.os_id = ?',$id);
        $query->order(array('os_name','cp_name'));
        return $this->db->fetchAll($query);
    }
    //Them mới user
    public function insertcp(){
    	$data = array(
    			'os_id' => $this->os_id,
    			'cp_name' => $this->cp_name,
    			'cp_status'=>$this->cp_status,
    	);
    	//var_dump($data); die;
    	return $this->db->insert($this->_name,$data);
    }
    
    public function updatecp(){
    	$data = array(
    			'os_id' => $this->os_id,
    			'cp_name' => $this->cp_name,
    			'cp_status'=>$this->cp_status,
    	);
    	$where = array('cp_id =?'=>$this->cp_id);
    	//var_dump($data); die;
    	return $this->db->update($this->_name,$data,$where);
    }
    //Xoa theo os_id
    public function deleteID($id){
    	$where = array('cp_id =?'=>$id);
    	return $this->db->delete($this->_name,$where);
    }

}

